package com.dubbo.hyp;

import com.dubbo.hyp.bean.ConsumerComponent;
import com.dubbo.hyp.thread.ConsumerThread;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.*;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class AnnotationConsumerMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ConsumerComponent service = context.getBean(ConsumerComponent.class);

        ExecutorService executorServiceA = Executors.newFixedThreadPool(1000);
        ExecutorService executorServiceB = Executors.newFixedThreadPool(1000);
        ExecutorService executorServiceC = Executors.newFixedThreadPool(1000);

        executorServiceA.submit(new ConsumerThread("A", service));
        executorServiceB.submit(new ConsumerThread("B", service));
        executorServiceC.submit(new ConsumerThread("C", service));


//        executorServiceA.submit(new ConsumerThread("A", service));
//        executorServiceB.submit(new ConsumerThread("B", service));
//        executorServiceC.submit(new ConsumerThread("C", service));

        System.in.read();
//        while (true) {
//            service.getTimeA();
//            service.getTimeB();
//            service.getTimeC();
//            executorServiceA.submit(new ConsumerThread("A", service));
//            executorServiceB.submit(new ConsumerThread("B", service));
//            executorServiceC.submit(new ConsumerThread("C", service));
//        }
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    //@EnableDubbo(scanBasePackages = "com.lagou.bean")
    @ComponentScan("com.dubbo.hyp.bean")
    @EnableDubbo
    static class ConsumerConfiguration {
        @Bean
        public RegistryConfig registryConfig() {
            RegistryConfig registryConfig = new RegistryConfig();
            registryConfig.setAddress("zookeeper://127.0.0.1:2181?timeout=10000");
            registryConfig.setTimeout(10000);
            return registryConfig;
        }
    }
}
